#ifndef __OBJEV_TYPE_H__
#define __OBJEV_TYPE_H__

#define MEDUSA_VERSION "medusa-cpp 0.1 alpha"

#define IN
#define OUT
#define BOTH

// assert
#include <assert.h>
#if MEDUSA_DISABLE_ASSERT > 0
#define MEDUSA_ASSERT(cond)
#else
#define MEDUSA_ASSERT(cond) assert(cond)
#endif

//#include "platform/CCPlatformConfig.h"
//#include "platform/CCPlatformMacros.h"

// namespace medusa {}
#ifdef __cplusplus
#define NS_MEDUSA_BEGIN                     namespace medusa {
#define NS_MEDUSA_END                       }
#define USING_NS_MEDUSA                     using namespace medusa
#else
#define NS_MEDUSA_BEGIN
#define NS_MEDUSA_END
#define USING_NS_MEDUSA
#endif

// define C99 equivalent types.
// win32
#if defined(WIN32) && defined(_WINDOWS)
typedef signed char           int8_t;
typedef signed short          int16_t;
typedef signed int            int32_t;
typedef signed long long      int64_t;
typedef unsigned char         uint8_t;
typedef unsigned short        uint16_t;
typedef unsigned int          uint32_t;
typedef unsigned long long    uint64_t;
#else
#include <stdint.h>
#endif
typedef uint8_t byte;
typedef float   float32_t;
typedef double  float64_t;


/*
//Windows: complie it with vc++ 6.0 IDE
//RedHat Linux: gcc -o test test.c
//Soloaris9:  gcc -o test test.c -lsocket -lresolv 
//FreeBsd:   gcc -o test test.c  

#define final_class class
#define implement


//#define _CRT_SECURE_NO_DEPRECATE 
#include <stdio.h>
#include <string>


struct HostInfo
{
public:
    HostInfo()
    {
        ::memset(this, 0, sizeof(HostInfo));
    }
    HostInfo(const std::string& ip, int port)
    {
        ::strcpy(this->ip, ip.c_str());
        this->port = port;
    }

    HostInfo(const HostInfo& info)
    {
        ::strcpy(this->ip, info.ip);
        this->port = info.port;
    }

    HostInfo& operator=(const HostInfo& info)
    {
        ::strcpy(this->ip, info.ip);
        this->port = info.port;
        return *this;
    }

    bool operator==(const HostInfo& info) const
    {
        if(this->port!=info.port)
            return false;
        return ::strcmp(this->ip, info.ip)==0; 
    }

    std::string ToString()
    {
        char buf[24]={0};
        ::sprintf(buf, "[%s:%d]", this->ip, this->port);
        return buf;
    }
public:
    char    ip[16];
    int     port;
};

struct CompareHostinfo
{  
    //typedef std::pair<int, int> value_type;  
    bool operator () (const HostInfo& a, const HostInfo& b)  
    {  
        //if(a.port==b.port)
            //return false;
        //return ::strcmp(a.ip, b.ip)==0;
        return (a.port < b.port || (a.port==b.port && ::strcmp(a.ip, b.ip)<0) );
        //return a==b;
    }
};

#include <exception> //define errno_t

#ifdef   _WIN32
//---------------------------------------------------
//#include "win/type_windows.h" 
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")

#include <mswsock.h>    //Œ¢»Ì¿©’πµƒ¿‡ø‚
#pragma comment(lib, "mswsock.lib")
#include <windows.h>

typedef SOCKET  socket_t;
typedef HANDLE  thread_t;
typedef HANDLE  watch_t;
//typedef LONG    uuid;
typedef CRITICAL_SECTION    mutex_lock_t;

#define THREAD_API DWORD WINAPI

// tbb
#include <tbb/tbb.h>
#ifdef _DEBUG
#pragma comment(lib, "tbb_debug.lib")
#else
#pragma comment(lib, "tbb.lib")
#endif //_DEBUG
//using namespace tbb;

// define C99 equivalent types.
typedef signed char           int8_t;
typedef signed short          int16_t;
typedef signed int            int32_t;
typedef signed long long      int64_t;
typedef unsigned char         uint8_t;
typedef unsigned short        uint16_t;
typedef unsigned int          uint32_t;
typedef unsigned long long    uint64_t;

//Ãÿ ‚¿‡–Õ
//typedef int  error_t;	            //¥ÌŒÛ÷µ£¨ø…“‘Œ™∏∫ ˝ ±»»Á£∫-95,-96
//typedef unsigned int  index_t;    //-1±Ì æ≤ª‘⁄À˜“˝∑∂Œß
//typedef unsigned int  count_t;	//◊‹ ˝£¨≤ªø…“‘Œ™∏∫ ˝

#else

//for unix platform like Linux8,9 and Fedoral ,Solaris9 and freebsd


typedef int  socket_t;
typedef int  thread_t;
typedef int  watch_t;

// define C99 equivalent types.
#include <stdint.h>



#endif //#ifdef _WIN32 

#ifdef __FreeBSD__
#include <netinet/in.h>
#include <arpa/inet.h>
#endif //__FreeBSD__

#ifdef __SunOS__

//you need to link this file with option -lsocket -lresolv
//gcc -o test  test.c -lsocket -lresolv

#endif //__SunOS__
*/

#endif //__OBJEV_TYPE_H__
